#include <vector>
#include <iostream>
#include <string>
#include <ranges>
#include <any>
#include <string>

/**
 * @brief ranges demo
 * @note MSVC:The contents of <ranges> are available only in c++latest mode with concepts support;
 * @note Please add compile options "/std:c++latest"
 */

void test1()
{
    auto ints = std::views::iota(0, 10);
    auto even = [](int i)
    { return 0 == i % 2; };
    auto square = [](int i)
    { return i * i; };

    for (int i : ints | std::views::filter(even) | std::views::transform(square))
        std::cout << i << ' ';
}

template <std::ranges::view T>
auto make_vector(T a)
{
    return std::vector(a.begin(), a.end());
}

int main()
{
    test1();
    std::cout << std::endl;

    std::any x = std::vector{1, 2, 3, 4};
    x = make_vector(std::views::all(any_cast<std::vector<int> &>(x)) | std::views::transform([](int x)
                                                                                             { return std::to_string(x); }));

    for (const auto &i : std::any_cast<std::vector<std::string> &>(x))
    {
        std::cout << i << ", ";
    }
}
